# -*-coding: utf-8 -*-
"""
    @Theme   : Tornado Hello World!
    @Time    : 2024/4/7 21:12
    @Author  : YamFish
    @Url     : https://www.zhihu.com/people/yamfish
"""
import os

from tornado.web import RequestHandler, Application
from tornado.ioloop import IOLoop


class IndexHandler(RequestHandler):
    """Index Handler"""

    def get(self):
        return self.write("Hello World!")


class LoginHandler(RequestHandler):
    def get(self):
        self.render('login.html')

    def post(self):
        username = self.get_argument('username')
        password = self.get_argument('password')
        self.write(f'username = {username!r}, password = {password!r}')


def make_app():
    """Create Tornado Application"""
    routes = [
        (r'/', IndexHandler),
        (r'/login', LoginHandler),
    ]

    return Application(
        routes,
        debug=True,
        template_path=os.path.join(os.path.dirname(__file__), 'templates'),
        static_path=os.path.join(os.path.dirname(__file__), 'static')
    )


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)

    print('Serving on Port 8888...')
    IOLoop.current().start()
